﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Animation;

namespace SharPy.Interface
{
    class clAnimations
    {
        internal static async void AnimatePage(Page pageRoot, string p)
        {
            switch (p)
            {
                case "horizontalPunch":
                    //await HorizontalPunch(pageRoot as GamePage, null);
                    break;
                case "verticalPunch":
                    //await VerticalPunch(pageRoot as GamePage, null);
                    break;
                default:
                    break;
            }
        }
        public async static Task<int> Glow(GamePage page, UIElement pTarget, double pTimeSpan = 1)
        {
            DoubleAnimation myDoubleAnimation = new DoubleAnimation();
            myDoubleAnimation.From = 1.0;
            myDoubleAnimation.To = 0.0;
            myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(pTimeSpan));
            myDoubleAnimation.AutoReverse = true;
            myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;

            page.AnimationStoryboard = new Storyboard();
            page.AnimationStoryboard.Children.Add(myDoubleAnimation);
            Storyboard.SetTarget(myDoubleAnimation, pTarget);
            Storyboard.SetTargetProperty(myDoubleAnimation, "Opacity");
            page.AnimationStoryboard.Begin();

            return 0;
        }
        public async static Task<int> FadeIn(GamePage page, UIElement pTarget, double pTimeSpan = 1)
        {
            DoubleAnimation myDoubleAnimation = new DoubleAnimation();
            myDoubleAnimation.From = 0.0;
            myDoubleAnimation.To = 1.0;
            myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(pTimeSpan));

            page.AnimationStoryboard = new Storyboard();
            page.AnimationStoryboard.Children.Add(myDoubleAnimation);
            Storyboard.SetTarget(myDoubleAnimation, pTarget);
            Storyboard.SetTargetProperty(myDoubleAnimation, "Opacity");
            page.AnimationStoryboard.Begin();

            return 0;
        }
        public async static Task<int> FadeOut(GamePage page, UIElement pTarget, double pTimeSpan = 1)
        {
            DoubleAnimation myDoubleAnimation = new DoubleAnimation();
            myDoubleAnimation.From = 1.0;
            myDoubleAnimation.To = 0.0;
            myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(pTimeSpan));

            page.AnimationStoryboard = new Storyboard();
            page.AnimationStoryboard.Children.Add(myDoubleAnimation);
            Storyboard.SetTarget(myDoubleAnimation, pTarget);
            Storyboard.SetTargetProperty(myDoubleAnimation, "Opacity");
            page.AnimationStoryboard.Begin();

            return 0;
        }

        public async static Task<int> VerticalPunch(GamePage page, UIElement pTarget, double pTimeSpan = 1)
        {
            DoubleAnimation myDoubleAnimation = new DoubleAnimation();
            myDoubleAnimation.From = 50;
            myDoubleAnimation.To = 500;
            myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(pTimeSpan));
            myDoubleAnimation.AutoReverse = true;

            page.AnimationStoryboard = new Storyboard();
            page.AnimationStoryboard.Children.Add(myDoubleAnimation);
            Storyboard.SetTarget(myDoubleAnimation, page.FindName("imBackground") as Image);
            Storyboard.SetTargetProperty(myDoubleAnimation, "Y");
            page.AnimationStoryboard.Begin();

            return 0;
        }
        public async static Task<int> HorizontalPunch(GamePage page, UIElement pTarget, double pTimeSpan = 1)
        {
            DoubleAnimation myDoubleAnimation = new DoubleAnimation();
            myDoubleAnimation.From = 1.0;
            myDoubleAnimation.To = 0.0;
            myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(pTimeSpan));

            page.AnimationStoryboard = new Storyboard();
            page.AnimationStoryboard.Children.Add(myDoubleAnimation);
            Storyboard.SetTarget(myDoubleAnimation, page.FindName("imBackground") as Image);
            Storyboard.SetTargetProperty(myDoubleAnimation, "X");
            page.AnimationStoryboard.Begin();

            return 0;
        }



    }
}
